/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade.modules.system.controller;



import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;

import org.springblade.modules.system.entity.DrugsType;

import org.springblade.modules.system.service.IDrugsTypeService;

import org.springblade.utils.PageBounds;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;


/**
 * 控制器
 *
 * @author Chill
 */
@Api("drugsType")
@RestController
@RequestMapping("/drugsType")
@AllArgsConstructor
public class DrugsTypeController {

	private IDrugsTypeService drugsTypeService;


	/**
	 * 分页查询所有类型
	 *
	 * @param drugsType
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@ApiOperation(value = "显示所有")
	@RequestMapping(value = "/openDrugsTypeTable", method = RequestMethod.POST)
	public HashMap<String, Object> openDrugsTypeTable(DrugsType drugsType, Integer currentPage, Integer pageSize) {
		HashMap<String, Object> result = new HashMap<>();
		PageBounds<DrugsType> pageBounds=drugsTypeService.showAllDrugsType(drugsType,currentPage,pageSize);
		result.put("data",pageBounds);
		return result;
	}

	/**
	 * 增加药品类型
	 *
	 * @param drugsType
	 * @return
	 */
	@ApiOperation(value = "添加类型")
	@ResponseBody
	@RequestMapping(value = "/addDrugsType",method = RequestMethod.POST)
	public HashMap<String, Object> addDrugsType(DrugsType drugsType) {
		HashMap<String, Object> result = new HashMap<String, Object>();
		drugsTypeService.addDrugsType(drugsType);
		return result;
	}

	/**
	 * 删除类型判断
	 *
	 * @param typeid
	 * @return
	 */
	@ApiOperation(value = "判断类型是否可以删除")
	@ResponseBody
	@RequestMapping(value = "/delDrugsType", method = RequestMethod.POST)
	public HashMap<String, Object> delDrugsType(Integer[] typeid) {
		HashMap<String, Object> result = new HashMap<>();
		int m= drugsTypeService.delDrugsType(Arrays.asList(typeid));
		result.put("number",m);
		return result;
	}

	/**
	 * 单个删除
	 *
	 * @param id
	 * @return
	 */
	/*@ResponseBody
	@RequestMapping("/deleteDrugsType")
	public HashMap<String, Object> deleteDrugsType(Integer id) {
		HashMap<String, Object> result = new HashMap<>();
		drugsTypeService.deleteDrugsType(id);
		return result;
	}*/

	/**
	 * 按id批量删除
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@ApiOperation(value = "批量删除")
	@ResponseBody
	@RequestMapping(value = "/deleteMoreDrugsPtype", method = RequestMethod.POST)
	public HashMap<String, Object> deleteMoreDrugsPtype(Integer[] ids) throws Exception {
		HashMap<String, Object> result = new HashMap<>();
		drugsTypeService.deleteMoreDrugsPtype(Arrays.asList(ids));
		return result;
	}

	/**
	 * 修改药品类型
	 *
	 * @param drugsType
	 * @return
	 */
	@ApiOperation(value = "修改类型")
	@ResponseBody
	@RequestMapping(value = "/updateDrugsType", method = RequestMethod.POST)
	public HashMap<String, Object> updateDrugsType(DrugsType drugsType) {
		HashMap<String, Object> result = new HashMap<>();
		drugsTypeService.updateDrugsType(drugsType);
		return result;
	}

}
